using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;

public class ShowCargoGrid : MonoBehaviour
{
    public CargoList cargoList;
    public GameObject prefab;
    public void CreateCargoGrid(Dictionary<int, int> cargoDict)
    {
        foreach (int cargoID in cargoDict.Keys)
        {
            CreateCargoGridItem(cargoID, cargoDict[cargoID]);
        }

    }

    public void ClearCargoGrid()
    {
        foreach (Transform child in transform)
        {
            Destroy(child.gameObject);
        }
    }


    void CreateCargoGridItem(int cargoID, int count)
    {
       
        GameObject newObject = Instantiate(prefab, transform.position, Quaternion.identity);
        newObject.transform.SetParent(transform, false);
        TextMeshProUGUI textMesh = newObject.GetComponentInChildren<TextMeshProUGUI>();

        textMesh.text = "Cargo: " + cargoList.GetCargoByID(cargoID).cargoName + "\nNumber: " + count;
    }
}
